package com.example.prom.dangwen.y2023.thread;

import lombok.SneakyThrows;

public class PrintThead03 {
    static class MyThead03 implements Runnable{

        private String symbol;
        private int value;
//        private int total;
        private static volatile int counter = 0;

        public MyThead03(String symbol, int value, int total){
            this.symbol = symbol;
//            this.total = total;
            this.value = value;
        }

        private static final Object objLock = new Object();

        @SneakyThrows
        @Override
        public void run() {
            synchronized (objLock){
                for (int i = 0; i < 10; i++) {
                    while (counter % 3 != value){
                        objLock.wait();
                    }
                    System.out.println(symbol);
                    counter++;
                    objLock.notifyAll();
                }
            }
        }
    }

    public static void main(String[] args) {
        Thread t1 = new Thread(new MyThead03("A", 0, 10));
        Thread t2 = new Thread(new MyThead03("B", 1, 1));
        Thread t3 = new Thread(new MyThead03("C", 2, 2));
        t1.start();
        t2.start();
        t3.start();
    }
}
